package com.wkhyapp.lm.adapter;


import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wkhyapp.lm.R;
import com.wkhyapp.lm.http.vo.Fans;
import com.wkhyapp.lm.http.vo.Goods;
import com.wkhyapp.lm.utils.GetTimeAgo;
import com.wkhyapp.lm.utils.ImageLoadUtil;

import java.util.List;

/**
 * Created by Administrator on 2021-10-6.
 */

public class GoodsXCListAdapter extends BaseQuickAdapter<Goods, BaseViewHolder> {

    public GoodsXCListAdapter.callBack mCallBack;
    public GoodsXCListAdapter(int layoutResId, List<Goods> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, final Goods item) {
        ImageView imageView = helper.getView(R.id.goods_iv);
        ImageLoadUtil.setRoundImage_Normal(mContext,item.getImg(),6,imageView);
        helper.setText(R.id.title_tv,item.getDesc());
        RelativeLayout goods_rl = helper.getView(R.id.goods_rl);
        helper.setText(R.id.imgCount_tv,item.getImgCount()+"");
        TextView setTop_tv = helper.getView(R.id.setTop_tv);
        if(item.getTopTime()>0){
            setTop_tv.setText("取消置顶");
        }else{
            setTop_tv.setText("永久置顶");
        }



        TextView del_tv = helper.getView(R.id.del_tv);
        TextView down_tv = helper.getView(R.id.down_tv);
        helper.setText(R.id.time_tv, GetTimeAgo.getTimeAgo(item.getUpdateTime()));
        TextView share_but = helper.getView(R.id.share_but);

        share_but.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBack.share(item);
            }
        });
        goods_rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBack.info(item);
            }
        });

        del_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBack.del(item);
            }
        });

        down_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBack.down(item);
            }
        });

        setTop_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mCallBack.setTop(item);
            }
        });
    }

    public void  setCallBack(GoodsXCListAdapter.callBack callBack){
        this.mCallBack = callBack;
    }


    public interface  callBack{
        void del(Goods item);

        void down(Goods item);

        void setTop(Goods item);

        void info(Goods item);
        void share(Goods item);
    }

}
